"""
人类：
    属性:
    姓名，性别，年龄，所拥有的手机剩余话费，手机品牌，手机电池容量，手机屏幕大小，手机最大待机时长，所拥有的积分。
功能：
    发短信（要求参数传入短信内容）。
    打电话（要求传入要打的电话号码和要打的时间长度。程序里判断号码是否为空或者本人的话费是否小于1元，若为空或者小于1元则报相对应的错误信息，否则的话拨通。结束后，按照时间长度扣费并返回扣费并且按照分钟给手机卡累加积分（0~10分钟：1元/钟、15个积分/钟，10~20分钟：0.8元/钟、39个积分/钟，其他：0.65元/钟、48个积分/钟））

"""
import copy
import time

PHONE_CALL_POLICY={
    10:(1,15),
    20:(0.8,39),
    21:(0.65,48)
}
class Phone(object):
    def __init__(self,brand, battery_capacity, screen_size, maximum_standby_time):
        """手机品牌，手机电池容量，手机屏幕大小，手机最大待机时长"""
        self.brand = brand
        self.battery_capacity = battery_capacity
        self.screen_size = screen_size
        self.maximum_standby_time = maximum_standby_time
    def send_message(self,message):
        print(message)
    def make_call(self,phone_number,other_phone_number):
        start_time = time.time()  # 记录开始时间
        time.sleep(3) # 模拟打了3分钟，实际只是3秒
        # 打电话：吧啦吧啦
        end_time = time.time()  # 记录结束时间
        return end_time - start_time


class Person(object):
    def __init__(self, name,age,balance=0,*,brand='',phone_number='', battery_capacity=0, screen_size=0, maximum_standby_time=0,phone=None):
        self.name = name
        self.age = age
        self.balance = balance
        self.points = 0
        self.call_time=0
        self.phone_number=phone_number
        if  phone is not None:
            self.phone = copy.deepcopy(phone)
        else:
            self.phone = Phone(brand, battery_capacity, screen_size, maximum_standby_time)
    def set_phone_number(self,phone_number):
        self.phone_number=phone_number
    def get_phone_number(self):
        return self.phone_number
    def send_message(self,message):
        """用手机发短信"""
        self.phone.send_message(message)
        print('短信发送成功')
    def make_call(self,other_phone_number):
        """用手机打电话"""
        if self.balance <=1:
            print('余额不足，请充话费')
            return
        if other_phone_number==self.phone_number:
            print('自己不能给自己打电话')
            return
        elif other_phone_number is  None:
            print('您拨打的手机是空号，重新输入：')
            return
        print('已拨通，请收听：')
        self.call_time=self.phone.make_call(self.phone_number,other_phone_number)
        self.settlement()
    def settlement(self):
        """结算花费"""
        if self.call_time<=10:
            self.balance-=self.call_time*PHONE_CALL_POLICY[10][0]
            self.points+=self.call_time*PHONE_CALL_POLICY[10][1]
        elif self.call_time<=20:
            self.balance-=self.call_time*PHONE_CALL_POLICY[20][0]
            self.points+=self.call_time*PHONE_CALL_POLICY[20][1]
        else:
            self.balance-=self.call_time*PHONE_CALL_POLICY[21][0]
            self.points+=self.call_time*PHONE_CALL_POLICY[21][1]
        self.call_time=0
        self.balance=round(self.balance,2)
        self.points=int(self.points)

if __name__ == '__main__':
    phone=Phone('vivo','40','50','24')
    p=Person('crocuser','22',50,phone=phone)
    p.set_phone_number('111111')
    p.send_message('hello world')
    p.make_call('222222')
    print(p.__dict__)
    print(p.phone.__dict__)